package com.zcx.qshop.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;
import com.zcx.qshop.R;
import com.zcx.qshop.QSApplication;
import com.zcx.qshop.conn.JsonGetpasswordAsyGet;

/**
 * Created by Administrator on 2015/9/19 0019.
 */
public class EditPasswordActivity extends QSActivity implements View.OnClickListener{

    @BoundView(R.id.edit_password_back) private View back;

    @BoundView(R.id.edit_password_password) private EditText password;

    @BoundView(R.id.edit_password_password_delete) private View password_delete;

    @BoundView(R.id.edit_password_confirm_password) private EditText confirm_password;

    @BoundView(R.id.edit_password_confirm_password_delete) private View confirm_password_delete;

    @BoundView(R.id.edit_password_edit) private View edit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_edit_password);

        back.setOnClickListener(this);

        password_delete.setOnClickListener(this);

        confirm_password_delete.setOnClickListener(this);

        edit.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){

            case R.id.edit_password_back:

                finish();

                break;

            case R.id.edit_password_password_delete:

                password.setText("");

                break;

            case R.id.edit_password_confirm_password_delete:

                confirm_password.setText("");

                break;

            case R.id.edit_password_edit:

                String psd = password.getText().toString(), cpsd = confirm_password.getText().toString();

                if(psd.equals("")||cpsd.equals("")){

                    UtilToast.show(this, "密码不能为空");

                    return;

                }else if(!cpsd.equals(psd)){

                    UtilToast.show(this, "两次输入的密码不同");

                }else{

                    new JsonGetpasswordAsyGet(getIntent().getStringExtra("username"), password.getText().toString(), new AsyCallBack(){

                        @Override
                        public void onSuccess(String toast, int type, Object o) throws Exception {

                            QSApplication.INSTANCE.finishActivity(GetBackActivity.class);

                            finish();

                        }

                        @Override
                        public void onEnd(String toast, int type) throws Exception {

                            UtilToast.show(EditPasswordActivity.this, toast);

                        }

                    }).execute(this);

                }

                break;

        }

    }

}
